class Solution {
public:

    bool searchMatrix(vector<vector<int>>& matrix, int target) {
       //遇到二维数组，最好的选择是转化为一位数组去用
       // size = nums[0].size()   len = nums.size();=> begin = 0, end = size*len-1
       //index在 [index/size][index%size]   3*4=>index=5（第5+1个元素）   在 第1+1行，第1+1个
       int size = matrix[0].size(),len = matrix.size();
       int begin = 0,end = size*len-1;
       int mid;
       while(begin<=end){
            mid = begin+((end-begin)>>1);
           if (matrix[mid/size][mid%size]==target) return true;
           else if (matrix[mid/size][mid%size]>target){
               end = mid-1;
           }else begin = mid +1;
       }

        return false;
    }
};